package com.itfreer.data.metadata.entity;

import java.io.Serializable;
import java.util.LinkedHashSet;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.OneToMany;
import javax.persistence.OrderBy;
import javax.persistence.Transient;

import com.itfreer.form.api.entity.EntityBase;
import com.itfreer.form.api.reflect.DictionaryField;

/**
 * 定义数据定义实体
 */
@Entity(name = "data_definition")
public class DataDefinitionEntity extends EntityBase implements Serializable {

	private static final long serialVersionUID = -8443497714033818376L;

	/**
	 * 主键
	 */
	@Id
	@Column(name = "id", length = 50, nullable = true)
	private String id;

	/**
	 * 数据名称
	 */
	@Column(name = "s_dataname", length = 30, nullable = true)
	private String dataname;

	/**
	 * 表空间
	 */
	@Column(name = "s_tableSpace", length = 30, nullable = true)
	private String tableSpace;

	/**
	 * 数据表名
	 */
	@Column(name = "s_datatable", length = 30, nullable = true)
	private String datatable;

	/**
	 * 数据类型
	 */
	@Column(name = "s_datatype", length = 10, nullable = true)
	@DictionaryField(dictionaryName = "d_table_type", toFieldName = "datatypename")
	private String datatype;

	/**
	 * 数据类型名称
	 */
	@Transient
	private String datatypename;

	/**
	 * 是否有效
	 */
	@Column(name = "b_valid", nullable = true)
	private Boolean valid;

	/**
	 * 排序值
	 */
	@Column(name = "i_order", nullable = true)
	private Integer order;

	/**
	 * 元数据
	 */
	@Column(name = "s_metadata", nullable = true)
	@DictionaryField(dictionaryName = "f_metadata_directory", toFieldName = "metadataName")
	private String metadata;

	/**
	 * 元数据别名
	 */
	@Transient
	private String metadataName;

	/**
	 * 空间坐标系统
	 */
	@Column(name = "s_spatialReference", length = 30, nullable = true)
	private String spatialReference;

	/**
	 * objectid字段
	 */
	@Column(name = "s_objectIdFieldName", length = 30, nullable = true)
	private String objectIdFieldName;

	/**
	 * 市县乡村的字段名称 用于数据上传下载同步时的锁定依据
	 */
	@Column(name = "s_adminFields", length = 30, nullable = true)
	private String adminFields;

	/**
	 * 图片字段 用于图片上传下载
	 */
	@Column(name = "s_imageField", length = 30, nullable = true)
	private String imageField;
	
	/**
	 * 是否是外部数据库
	 */
	@Column(name = "b_outdatabase", nullable = true)
	private Boolean outdatabase;

	/**
	 * 外部数据库驱动
	 */
	@Column(name = "s_driver", length = 200, nullable = true)
	private String driver;

	/**
	 * 外部数据库地址
	 */
	@Column(name = "s_url", length = 200, nullable = true)
	private String url;

	/**
	 * 外部数据库用户名
	 */
	@Column(name = "s_username", length = 50, nullable = true)
	private String username;

	/**
	 * 外部数据库密码
	 */
	@Column(name = "s_password", length = 50, nullable = true)
	private String password;

	/**
	 * 子表对象
	 */
	@OneToMany(cascade = { CascadeType.ALL }, fetch = FetchType.EAGER)
	@JoinColumn(name = "pid")
	@OrderBy("i_order ASC")
	private Set<DataDefinitionSubEntity> subs = new LinkedHashSet<>();

	/**
	 * 租户ID
	 */
	@Column(name = "s_tenantID", length = 50, nullable = true)
	private String tenantID;

	/**
	 * 租户名称
	 */
	@Column(name = "s_tenantName", length = 50, nullable = true)
	private String tenantName;

	/**
	 * 共享租户ID
	 */
	@Column(name = "s_shareTenantID", nullable = true, columnDefinition = "text")
	private String shareTenantID;

	/**
	 * 共享租户名称
	 */
	@Column(name = "s_shareTenantName", nullable = true, columnDefinition = "text")
	private String shareTenantName;

	/**
	 * 主键
	 */
	public void setId(String value) {
		this.id = value;
	}

	/**
	 * 数据名称
	 */
	public void setDataname(String value) {
		this.dataname = value;
	}

	/**
	 * 数据类型
	 */
	public void setDatatype(String value) {
		this.datatype = value;
	}

	/**
	 * 数据表名
	 */
	public void setDatatable(String value) {
		this.datatable = value;
	}

	/**
	 * 是否有效
	 */
	public void setValid(Boolean value) {
		this.valid = value;
	}

	/**
	 * 排序值
	 */
	public void setOrder(Integer value) {
		this.order = value;
	}

	@Transient
	public String getDatatypename() {
		return datatypename;
	}

	public void setDatatypename(String datatypename) {
		this.datatypename = datatypename;
	}

	public void setMetadata(String metadata) {
		this.metadata = metadata;
	}

	public void setSpatialReference(String spatialReference) {
		this.spatialReference = spatialReference;
	}

	public void setObjectIdFieldName(String objectIdFieldName) {
		this.objectIdFieldName = objectIdFieldName;
	}

	public void setTableSpace(String tableSpace) {
		this.tableSpace = tableSpace;
	}

	@Transient
	public String getMetadataName() {
		return metadataName;
	}

	public void setMetadataName(String metadataName) {
		this.metadataName = metadataName;
	}

	public void setAdminFields(String adminFields) {
		this.adminFields = adminFields;
	}

	public void setImageField(String imageField) {
		this.imageField = imageField;
	}

	/**
	 * 租户ID
	 */
	public void setTenantID(String tenantID) {
		this.tenantID = tenantID;
	}

	/**
	 * 租户名称
	 */
	public void setTenantName(String tenantName) {
		this.tenantName = tenantName;
	}

	/**
	 * 主键
	 */
	public String getId() {
		return id;
	}

	/**
	 * 数据名称
	 */
	public String getDataname() {
		return dataname;
	}

	/**
	 * 数据类型
	 */
	public String getDatatype() {
		return datatype;
	}

	/**
	 * 数据表名
	 */
	public String getDatatable() {
		return datatable;
	}

	/**
	 * 是否有效
	 */
	public Boolean getValid() {
		return valid;
	}

	/**
	 * 排序值
	 */
	public Integer getOrder() {
		return order;
	}

	/**
	 * 元数据
	 */
	public String getMetadata() {
		return metadata;
	}

	/**
	 * 空间坐标系统
	 */
	public String getSpatialReference() {
		return spatialReference;
	}

	/**
	 * objectid字段
	 */
	public String getObjectIdFieldName() {
		return objectIdFieldName;
	}

	/**
	 * 表空间
	 */
	public String getTableSpace() {
		return tableSpace;
	}

	/**
	 * 市县乡村的字段名称 用于数据上传下载同步时的锁定依据
	 */
	public String getAdminFields() {
		return adminFields;
	}

	/**
	 * 市县乡村的字段名称 用于数据上传下载同步时的锁定依据
	 */
	public String getImageField() {
		return imageField;
	}

	public Boolean getOutdatabase() {
		return outdatabase;
	}

	public void setOutdatabase(Boolean outdatabase) {
		this.outdatabase = outdatabase;
	}

	public String getDriver() {
		return driver;
	}

	public void setDriver(String driver) {
		this.driver = driver;
	}

	public String getUrl() {
		return url;
	}

	public void setUrl(String url) {
		this.url = url;
	}

	public String getUsername() {
		return username;
	}

	public void setUsername(String username) {
		this.username = username;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public Set<DataDefinitionSubEntity> getSubs() {
		return subs;
	}

	public void setSubs(Set<DataDefinitionSubEntity> subs) {
		this.subs = subs;
	}

	/**
	 * 租户ID
	 */
	public String getTenantID() {
		return tenantID;
	}

	/**
	 * 租户名称
	 */
	public String getTenantName() {
		return tenantName;
	}

	@Override
	public String getShareTenantID() {
		return shareTenantID;
	}

	@Override
	public void setShareTenantID(String shareTenantID) {
		this.shareTenantID = shareTenantID;
	}

	public String getShareTenantName() {
		return shareTenantName;
	}

	public void setShareTenantName(String shareTenantName) {
		this.shareTenantName = shareTenantName;
	}
}